package com.xiaocg.base.juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author xiaocg
 * 循环屏障
 */
public class CyclicBarrierDemo {
    public static void main(String[] args) {
        Runnable barrierAction;
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, ()->{
            System.out.println("ddddddddddddddd");
        });

        for (int i = 0; i < 7; i++) {
            new Thread(()->{
                System.out.println("当前线程:"+Thread.currentThread().getName());
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
